package com.vietnam.power.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/*we can use 'MD5 password encoder' or 'SHA encryption algorithms', but spring recommend 
 * us to use 'BCryptPasswordEncoder' a more stable and strong encryption algorithms.*/
public class HashCodeGenerator {
	private static final int strength = 10;

	// BCryptPasswordEncoder method
	public static String getHashPassword(String input) {
		BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(strength);
		String hashedPassword = passwordEncoder.encode(input);

		System.out.println(hashedPassword);
		return hashedPassword;
	}

	// BCryptPasswordEncoder method
	public static boolean checkHashPassword(String rawPassword, String encodedPassword) {
		BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(strength);
		return passwordEncoder.matches(rawPassword, encodedPassword);
	}

	public static void main(String[] args) {
		getHashPassword("password");
	}
}
